package javaCode;

import java.util.*;

public class LeetCode530 {
	 public int getMinimumDifference(TreeNode root) {
		 if(root == null){
			 return 0; 
		 }
		 List<Integer> list = new ArrayList<>();
	    backTrace(root, list);
	    int []nums = new int[list.size()];
	    for(int i =0;i < list.size();i++){
	    	nums[i] = list.get(i);
	    }
	    Arrays.sort(nums);
	    int max = nums[list.size()-1];
	    for(int i = 1;i < nums.length;i++){
	    	int tem = nums[i]-nums[i-1];
	    	max = Math.min(tem, max);
	    }
	    System.out.println(max);
		 return max;
	 }
	 public void backTrace(TreeNode root,List<Integer> list){
		 if(root == null){
			 return;
		 }
		 list.add(root.val);
		 backTrace(root.left, list);
		 backTrace(root.right, list);
	 }
	 
	 
}
	 
